<?php
function auth(){
	return 2;
}


function monthPullDown($month, $montharray) {// acho q nao sera utilizado
	echo "\n<select name=\"month\">\n";

	for($i=0;$i < 12; $i++) {
		if ($i != ($month - 1))
		echo "	<option value=\"" . ($i + 1) . "\">$montharray[$i]</option>\n";
		else
		echo "	<option value=\"" . ($i + 1) . "\" selected>$montharray[$i]</option>\n";
	}

	echo "</select>\n\n";
}

function yearPullDown($year) {// acho q nao sera utilizado
	echo "<select name=\"year\">\n";

	$z = 3;
	for($i=1;$i < 8; $i++) {
		if ($z == 0){
			echo "	<option value=\"" . ($year - $z) . "\" selected>" . ($year - $z) . "</option>\n";
		}else{
			echo "	<option value=\"" . ($year - $z) . "\">" . ($year - $z) . "</option>\n";
		}

		$z--;
	}

	echo "</select>\n\n";
}

function dayPullDown($day) { // acho q nao sera utilizado
	echo "<select name=\"day\">\n";

	for($i=1;$i <= 31; $i++) {
		if ($i == $day) {
			echo "	<option value=\"$i\" selected>$i</option>\n";
		}else{
			echo "	<option value=\"$i\">$i</option>\n";
		}
	}

	echo "</select>\n\n";
}

function hourPullDown($hour, $namepre) {// acho q nao sera utilizado
	echo "\n<select name=\"" . $namepre . "_hour\">\n";

	for($i=0;$i <= 12; $i++) {
		if ($i == $hour) {
			echo "	<option value=\"$i\" selected>$i</option>\n";
		}else{
			echo "	<option value=\"$i\">$i</option>\n";
		}
	}

	echo "</select>\n\n";
}

function minPullDown($min, $namepre) { // acho q nao sera utilizado
	echo "\n<select name=\"" . $namepre . "_min\">\n";

	for($i=0;$i <= 55; $i+=5) {

		if ($i < 10) {
			$disp = "0" . $i;
		}else{
			$disp = $i;
		}

		if ($i == $min) {
			echo "	<option value=\"$i\" selected>$disp</option>\n";
		}else{
			echo "	<option value=\"$i\">$disp</option>\n";
		}
	}

	echo "</select>\n\n";
}

function amPmPullDown($pm, $namepre) { // acho q nao sera utilizado
	if ($pm) { $pm = " selected"; } else { $am = " selected"; }

	echo "\n<select name=\"" . $namepre . "_am_pm\">\n";
	echo "	<option value=\"0\"$am>am</option>\n";
	echo "	<option value=\"1\"$pm>pm</option>\n";
	echo "</select>\n\n";
}

function javaScript() { // parcial
?>
	<script language="JavaScript">
	function submitMonthYear() {
		document.monthYear.method = "post";
		document.monthYear.action = "index.jsp?reserva=1&pdatai=" + document.monthYear.pdatai.value;
		document.monthYear.submit();
	}

	function postMessage(day, month, year) {
		//eval("page" + day + " = window.open('mapa.jsp?d=" + day + "&m=" + month + "&y=" + year + "', 'postScreen', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=340,height=400');");
		eval("page" + day + " = showPopWin('mapa_ocupacional/mapa.jsp?d=" + day + "&m=" + month + "&y=" + year + "', 500, 380, null);");
	}

	function openPosting(pId) {
		//eval("page" + pId + " = window.open('mapa.jsp?id=" + pId + "', 'mssgDisplay', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=340,height=400');");
		eval("page" + day + " = showPopWin('mapa_ocupacional/mapa.jsp?d=" + day + "&m=" + month + "&y=" + year + "', 500, 380, null);");
	}

	function loginPop(month, year) {
		eval("logpage = window.open('mapa_ocupacional/login.php?month=" + month + "&year=" + year + "', 'mssgDisplay', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=340,height=400');");
	}
	</script>
<?php
}




function scrollArrows($d, $m, $y) {  //OK
	// set variables for month scrolling
	$nextyear = ($m != 12) ? $y : $y + 1;
	$prevyear = ($m != 1) ? $y : $y - 1;
	$prevmonth = ($m == 1) ? 12 : $m - 1;
	$nextmonth = ($m == 12) ? 1 : $m + 1;

	$s = "<a href=\"index.jsp?reserva=1&pdatai=$d/" . $prevmonth . "/" . $prevyear . "\">\n";
	$s .= "<img src=\"mapa_ocupacional/images/leftArrow.gif\" border=\"0\"></a> ";
	$s .= "<a href=\"index.jsp?reserva=1&pdatai=$d/" . $nextmonth . "/" . $nextyear . "\">";
	$s .= "<img src=\"mapa_ocupacional/images/rightArrow.gif\" border=\"0\"></a>";

	return $s;
}

function writeCalendar($pdatai) {

	list($Xday,$month,$year)=explode("/",$pdatai);

	$eventdata = getEventDataArray($pdatai);
	$eventcama = getCamasPorHabitacao($_SESSION["ID_HOSTEL_"]);



	//			echo"<pre>";
	//			print_r($eventcama);
	//			print_r($eventdata);
	//			echo"</pre>";
	//	exit;

	// get user permission level
	$auth = auth();

	// get number of days in month
	$days = 31-((($month-(($month<8)?1:0))%2)+(($month==2)?((!($year%((!($year%100))?400:4)))?1:2):0));
	$colums = 31;
	$nextmonth = ($month == 12) ? 1 : $month + 1;
	$daysnextmonth = ($colums + $Xday);
	$daynextmonth = 1;

	// get week position of first day of month.
	$weekpos = getFirstDayOfMonthPosition($Xday, $month, $year);
	$strInicio = getDayNameHeader($colums, $weekpos);
	$day = $Xday;

	// initialize today's date variables for color change
	$timestamp = mktime() + 0 * 3600;
	$d = date(j, $timestamp); $m = date(n, $timestamp); $y = date(Y, $timestamp);



	// loop writes empty cells until it reaches position of 1st day of month ($wPos)
	// it writes the days, then fills the last row with empty cells after last day
	############################################ inicio loop numero de dias ##############################################
	while($day <= $days) {

		$strDias .="<tr>\n
				    \t<td>&nbsp;</td>\n";

		for($i=0;$i < $colums; $i++) {
			if($day > 0 && $day <= $days) {
				$strDias .= "	<td class='column_header'>$day</td>\n";
				$day++;
			} elseif($day == 0)  {
				$strDias .= "	<td class='column_header'>&nbsp;</td>\n";
				$weekpos--;
				if ($weekpos == 0) {
					$day++;
				}
			} elseif($day <= $daysnextmonth && $day > $days) {
				$strDias .= "	<td class='column_header'>$daynextmonth&nbsp;</td>\n";
				$day++;
				$daynextmonth++;
			}
		}
		$strDias .= "</tr>\n\n";
	}
	############################################ fim loop numero de dias ##############################################



	// loop writes empty cells until it reaches position of 1st day of month ($wPos)
	// it writes the days, then fills the last row with empty cells after last day

	// initialize day variable to zero, unless $weekpos is zero
	$day = $Xday;


	$str ="";
	############################################ inicio loop habitacao ##############################################
	$sql="
	select 
		a.id_habitacao,
		a.num_habitacao,
		a.tp_habitacao,
		a.lotacao,
		a.id_bloco, 
		b.ds_bloco 
	from 
		hostel_habitacao a
		inner join hostel_bloco b on (a.id_bloco = b.id_bloco)
	where 
		a.id_hostel = {$_SESSION["ID_HOSTEL_"]} 
	order by 
		b.ds_bloco asc, 
		a.num_habitacao asc";

	//debug($sql);
	//require_once"funcoes/hostel_tp_habitacao.jsp"; // parece nao precisar carregar aqui, por ja estar sendo carregada na funcao eventdata

	$linha=$_SESSION['ADOCnn']->Execute("$sql");
	if($linha->RecordCount() != 0 ) {
		while(!$linha->EOF) {

			$lotacao 	  		= $linha->fields["lotacao"];
			$id_habitacao_ant 	= $id_habitacao;
			$id_habitacao 		= $linha->fields["id_habitacao"];
			$tipo_cobranca 		= getTpHabitacao($linha->fields["tp_habitacao"],"tipo_cobranca");
			$num_habitacao		= $linha->fields["num_habitacao"];

			$daynextmonth = 1;


			$str .="<tr>\n";
			$str .="\t<td class='column_header3 ' id='habit{$linha->fields["id_habitacao"]}bloco{$linha->fields["id_bloco"]}'>";
			$str .="<span class='time_str'>{$linha->fields["ds_bloco"]} </span><br>No:{$num_habitacao}<br>";
			$str .="<span class='time_str'>".getTpHabitacao($linha->fields["tp_habitacao"],"tipos_sigla")." </span>";
			$str .="</td>\n";




			############################################ inicio loop linha ##############################################
			while($day <= $days) {


				for($i=0;$i < $colums; $i++) {

					if($day > 0 && $day <= $days) {

						$str .= "	<td class=\"";

						if (($day == $d) && ($month == $m) && ($year == $y)) {
							$str .= "today";
						}else{
							$str .= "day";
						}

						$str .= "_cell day_number\">";

						if ($auth){
							$str .= "$day";
						}else{
							$str .= "$lotacao";
						}
						$str .= "<br>";


						################ inicio loop dia do mes ###########################################
						$eventdatacount = count($eventdata[$id_habitacao][$month."-".$day]["ID"]);
						if($tipo_cobranca == 1) {	// verifica se a forma de cobranca eh por cama ou habitacao

							for($j=0;$j < $eventdatacount;$j++) {

								$str .= "<a href=\"javascript:showPopWin2('mapa.jsp?pid_cama={$eventdata[$id_habitacao][$month."-".$day]["ID_CAMA"][$j]}&pid_reserva={$eventdata[$id_habitacao][$month."-".$day]["ID_RESERVA"][$j]}&pnum_habitacao={$num_habitacao}');\" class='{$eventdata[$id_habitacao][$month."-".$day]["CLASS"][$j]}'>";
								$str .= $eventdata[$id_habitacao][$month."-".$day]["NOME_PESSOA"][$j]."</a><br>";
							}
							$jj = (0 + $j);


							$eventdatacount_cinza = ($lotacao - $eventdatacount);
							$str_link_j = 1;
							for($j=0;$j < $eventdatacount_cinza;$j++) {
								//$dt_formatada = $y.str_pad($month,2,"0",STR_PAD_LEF).str_pad($day,2,"0",STR_PAD_LEF);
								$dt_formatada = $y.sprintf("%02d",$month).sprintf("%02d",$day);

								if ($str_link_j == 1) {
									######## verifica se o quarto coringa virou privativo, e se virou, nao permite reservar mais pessoas ###
									if ($eventdata[$id_habitacao][$month."-".$day]["COBRANCA_P_CAMA"][$j] === 0) {
										$str .= "<span class='comentario'>".$eventdata[$id_habitacao][$month."-".$day]["DS_TP_HABITACAO"][$j]."</span><a href=\"javascript:alert('N&atilde;o &eacute; poss&iacute;vel efetuar reserva. Habita&ccedil;&atilde;o foi transformada em privativa.');\" style='display:none; visibility:hidden;'>";
									}else{
										$str .= "<a href=\"javascript:showPopWin2('mapa.jsp?pid_cama={$eventcama[$id_habitacao][$jj]["ID_CAMA"]}&pdt_reserva=$dt_formatada&pnum_habitacao={$num_habitacao}');\">";
									}
								}
								$str .= "<img src='mapa_ocupacional/images/cama_cinza.gif' border='0'>";
								if ($str_link_j == 1) {
									$str .= "</a>";
								}

								$str .= "<br>";
								$jj++;
								$str_link_j++;
							}
						}else{
							if ($eventdatacount > 0) {
								$str .= "<a href=\"javascript:showPopWin2('mapa.jsp?pid_cama={$eventdata[$id_habitacao][$month."-".$day]["ID_CAMA"][0]}&pid_reserva={$eventdata[$id_habitacao][$month."-".$day]["ID_RESERVA"][0]}&pnum_habitacao={$num_habitacao}');\" class='{$eventdata[$id_habitacao][$month."-".$day]["CLASS"][0]}'>";
								$str .= $eventdata[$id_habitacao][$month."-".$day]["NOME_PESSOA"][0]."</a><br>";
							}else{
								//$dt_formatada = $y.str_pad($month,2,"0",STR_PAD_LEF).str_pad($day,2,"0",STR_PAD_LEF);
								$dt_formatada = $y.sprintf("%02d",$month).sprintf("%02d",$day);
								$str .= "<a href=\"javascript:showPopWin2('mapa.jsp?pid_cama={$eventcama[$id_habitacao][0]["ID_CAMA"]}&pdt_reserva=$dt_formatada&pnum_habitacao={$num_habitacao}');\">";
								$str .= "<img src='mapa_ocupacional/images/casa_cinza.gif' border='0'></a><br>";
							}
						}
						################ fim loop dia do mes ###########################################

						$str .= "</td>\n";
						$day++;
					} elseif($day == 0)  {
						$str .= "	<td class=\"empty_day_cell day_number\">&nbsp;</td>\n";
						$weekpos--;
						if ($weekpos == 0) {
							$day++;
						}
					} else {

						$str .= "	<td class=\"empty_day_cell day_number\">$daynextmonth<br>";

						################ inicio loop dia do proximo mes ###########################################
						$eventdatacount = count($eventdata[$id_habitacao][$nextmonth."-".$daynextmonth]["ID"]);
						if($tipo_cobranca == 1) {	// verifica se a forma de cobranca eh por cama ou habitacao

							for($j=0;$j < $eventdatacount;$j++) {
								$str .= "<a href=\"javascript:showPopWin2('mapa.jsp?pid_cama={$eventdata[$id_habitacao][$nextmonth."-".$daynextmonth]["ID_CAMA"][$j]}&pid_reserva={$eventdata[$id_habitacao][$nextmonth."-".$daynextmonth]["ID_RESERVA"][$j]}&pnum_habitacao={$num_habitacao}');\" class='{$eventdata[$id_habitacao][$nextmonth."-".$daynextmonth]["CLASS"][$j]}'>";
								$str .= $eventdata[$id_habitacao][$nextmonth."-".$daynextmonth]["NOME_PESSOA"][$j]."</a><br>";
							}

							$jj = (0 + $j);
							$eventdatacount_cinza = ($lotacao - $eventdatacount);
							$str_link_j = 1;
							for($j=0;$j < $eventdatacount_cinza;$j++) {
								//$dt_formatada = $y.str_pad($nextmonth,2,"0",STR_PAD_LEF).str_pad($daynextmonth,2,"0",STR_PAD_LEF);
								$dt_formatada = $y.sprintf("%02d",$nextmonth).sprintf("%02d",$daynextmonth);
								if ($str_link_j == 1) {
									######## verifica se o quarto coringa virou privativo, e se virou, nao permite reservar mais pessoas ###
									if ($eventdata[$id_habitacao][$nextmonth."-".$daynextmonth]["COBRANCA_P_CAMA"][$j] === 0) {
										$str .= "<a href=\"javascript:alert('N&atilde;o &eacute; poss&iacute;vel efetuar reserva. Habita&ccedil;&atilde;o foi transformada em privativa.');\">";
									}else{
										$str .= "<a href=\"javascript:showPopWin2('mapa.jsp?pid_cama={$eventcama[$id_habitacao][$jj]["ID_CAMA"]}&pdt_reserva=$dt_formatada&pnum_habitacao={$num_habitacao}');\">";
									}
								}
								$str .= "<img src='mapa_ocupacional/images/cama_cinza.gif' border='0'>";
								if ($str_link_j == 1) {
									$str .= "</a>";
								}
								$str .= "<br>";

								$jj++;
								$str_link_j++;
							}
						}else{
							if ($eventdatacount > 0) {
								$str .= "<a href=\"javascript:showPopWin2('mapa.jsp?pid_cama={$eventdata[$id_habitacao][$nextmonth."-".$daynextmonth]["ID_CAMA"][0]}&pid_reserva={$eventdata[$id_habitacao][$nextmonth."-".$daynextmonth]["ID_RESERVA"][0]}&pnum_habitacao={$num_habitacao}');\" class='{$eventdata[$id_habitacao][$nextmonth."-".$daynextmonth]["CLASS"][0]}'>";
								$str .= $eventdata[$id_habitacao][$nextmonth."-".$daynextmonth]["NOME_PESSOA"][0]."</a><br>";
							}else{
								//$dt_formatada = $y.str_pad($nextmonth,2,"0",STR_PAD_LEF).str_pad($daynextmonth,2,"0",STR_PAD_LEF);
								$dt_formatada = $y.sprintf("%02d",$nextmonth).sprintf("%02d",$daynextmonth);
								$str .= "<a href=\"javascript:showPopWin2('mapa.jsp?pid_cama={$eventcama[$id_habitacao][0]["ID_CAMA"]}&pdt_reserva=$dt_formatada&pnum_habitacao={$num_habitacao}');\">";
								$str .= "<img src='mapa_ocupacional/images/casa_cinza.gif' border='0'></a><br>";
							}
						}
						################ fim loop dia do proximo mes ###########################################
						$str .= "</td>\n";
						$daynextmonth++;
					}
				}
				$str .= "</tr>\n\n";
			}
			############################################ fim loop linha ##############################################

			$day = $Xday;

			$linha->MoveNext();
		} // bloco while
	}// bloco if
	############################################ fim loop habitacao ##############################################
	$strFim .= "</table>\n\n";

	return $strInicio.$strDias.$str.$strFim;
}

function getDayNameHeader($colums = 31, $weekpos) { //OK
	global $lang;
	// adjust day name order if weekstart not Sunday
	for($i=0; $i < $weekpos; $i++) {
		$tempday = array_shift($lang['abrvdays']);
		array_push($lang['abrvdays'], $tempday);
	}

	$s = "<table cellpadding=\"1\" cellspacing=\"1\" border=\"0\">\n
		<tr>\n
		\t<td>&nbsp;</td>\n
		";


	foreach($lang['abrvdays'] as $key => $day) {
		if ($key < $colums) {
			$s .= "\t<td class='column_header'>&nbsp;$day</td>\n";
		}

	}

	$s .= "</tr>\n\n";
	return $s;
}

function getEventDataArray($dt_inicio) { // dd/mm/yyyy  //OK


	list($dia,$mes,$ano)=explode("/",$dt_inicio);
	$dt_comeca_exibir  = date("Y-m-d", mktime(0, 0, 0, $mes  , $dia, $ano));
	$dt_termina_exibir  = date("Y-m-d", mktime(0, 0, 0, $mes  , $dia+30, $ano));

	$sql1 = "
	SELECT    
	    d.id_cama,
	    b.id_habitacao,
	    b.num_habitacao,
	    b.id_bloco,
	    e.ds_bloco,
	    b.tp_habitacao,
	    /*b.lotacao,*/
	    EXTRACT(DAY FROM a.dt_reserva_ini) as dia,
	    EXTRACT(MONTH FROM a.dt_reserva_ini) as mes,
	    EXTRACT(YEAR FROM a.dt_reserva_ini) as ano,
	    a.id_reserva,
	    a.data_cad_reserva,
	    a.dt_reserva_ini,
	    a.dt_reserva_fim,
	    a.nome as nome_pessoa,
	    a.reserva_confirmada,
	    a.dt_cancela_auto,
	    a.dt_checkin,
	    a.data_baixa,
	    a.vl_pg_total,
	    a.id_tp_habitacao
	 
	FROM
	    hostel_reservas a
	    inner join hostel_cama d on (a.id_cama = d.id_cama)
	    inner join hostel_habitacao b on (d.id_habitacao = b.id_habitacao)
	    inner join hostel_bloco e on (b.id_bloco = e.id_bloco)
	
	WHERE
	    (a.id_hostel = {$_SESSION["ID_HOSTEL_"]}) and
	   /* (EXTRACT(MONTH FROM a.dt_reserva_ini) = $mes) and
	    (EXTRACT(YEAR FROM a.dt_reserva_ini) = $ano) and*/
	    ((a.dt_reserva_ini between '$dt_comeca_exibir' and '$dt_termina_exibir') or
	    (a.dt_reserva_fim between '$dt_comeca_exibir' and '$dt_termina_exibir')) and
	    (a.cancelada = 0)
	order by b.id_habitacao, a.dt_reserva_ini
		";



	//debug($sql1);
	$row = $_SESSION['ADOCnn']->Execute("$sql1");

	require_once"funcoes/hostel_tp_habitacao.jsp";

	$j = 0;
	if($row->RecordCount() != 0 ){
		while(!$row->EOF){

			$id_habitacao 	  = $row->fields["id_habitacao"];
			$dif_dias =  dif_dias(str_replace("-","",$row->fields["dt_reserva_fim"]),str_replace("-","",$row->fields["dt_reserva_ini"]));
			list($ano,$mes,$dia)=explode("-",$row->fields["dt_reserva_ini"]);


			$class2 = "";
			if (date("Y-m-d H:i:s") > $row->fields["dt_cancela_auto"]) {
				$class2 = " tachado";
			}




			switch ($row->fields["reserva_confirmada"]) {
				case 0:
					$class = "amarelo";
					break;
				case 1:
					$class = "verde";
					break;
			}

			if ($row->fields["dt_checkin"] != null) {
				$class = "azul";
				$class2 = "";
			}



			if ($row->fields["data_baixa"] != "" and $row->fields["vl_pg_total"] > 0) {
				$class2 = " tachado";
			}






			for ($n=0;$n <= $dif_dias; $n++){ // solucao para exibir a pessoa menos 1 dia no mapa
				$novo_mesdia = date("n-j", mktime(0, 0, 0, $mes  , $dia+$n, $ano));
				$eventdata[$id_habitacao][$novo_mesdia]["ID"][] 			= $row->fields["id_habitacao"];

				$eventdata[$id_habitacao][$novo_mesdia]["NUM_HABITACAO"][] 	= $row->fields["num_habitacao"];
				$eventdata[$id_habitacao][$novo_mesdia]["ID_BLOCO"][]		= $row->fields["id_bloco"];
				$eventdata[$id_habitacao][$novo_mesdia]["DS_BLOCO"][]		= $row->fields["ds_bloco"];
				$eventdata[$id_habitacao][$novo_mesdia]["TP_HABITACAO"][]	= $row->fields["tp_habitacao"];
				//$eventdata[$id_habitacao][$novo_mesdia]["LOTACAO"][]		= $row->fields["lotacao"];
				$eventdata[$id_habitacao][$novo_mesdia]["MESDIA"][]			= $novo_mesdia;

				$eventdata[$id_habitacao][$novo_mesdia]["ID_RESERVA"][]		= $row->fields["id_reserva"];
				$eventdata[$id_habitacao][$novo_mesdia]["COBRANCA_P_CAMA"][]= getTpHabitacao($row->fields["id_tp_habitacao"]."-","tipo_cobranca");
				$eventdata[$id_habitacao][$novo_mesdia]["DS_TP_HABITACAO"][]= getTpHabitacao($row->fields["id_tp_habitacao"]."-","tipos_sigla");
				$eventdata[$id_habitacao][$novo_mesdia]["CLASS"][]			= $class.$class2;
				$eventdata[$id_habitacao][$novo_mesdia]["DATA_CAD_RESERVA"][]= $row->fields["data_cad_reserva"];
				$eventdata[$id_habitacao][$novo_mesdia]["DT_RESERVA_INI"][]	= $row->fields["dt_reserva_ini"];
				$eventdata[$id_habitacao][$novo_mesdia]["DT_RESERVA_FIM"][]	= $row->fields["dt_reserva_fim"];
				$eventdata[$id_habitacao][$novo_mesdia]["ID_CAMA"][]		= $row->fields["id_cama"];
				$eventdata[$id_habitacao][$novo_mesdia]["NOME_PESSOA"][]	= setNomeCurto($row->fields["nome_pessoa"]);

				$j++;
			}


			$row->MoveNext();
		}
	}

	return $eventdata;
	//	print_r($eventdata);
}



function getCamasPorHabitacao($id_hostel) {

	$sql="
	select 
		x.id_habitacao,
		x.id_cama		
	from 
		hostel_cama x
	where 
		x.id_hostel = $id_hostel 
	order by
		x.id_habitacao asc,
		x.id_cama asc";

	//debug($sql1);
	$row = $_SESSION['ADOCnn']->Execute("$sql");
	$j = 0;
	if($row->RecordCount() != 0 ){
		while(!$row->EOF){

			$id_habitacao_ant = $id_habitacao;
			$id_habitacao = $row->fields["id_habitacao"];

			if ($id_habitacao_ant != $id_habitacao) {$j = 0;}

			$eventcama[$row->fields["id_habitacao"]][$j]["ID_CAMA"] 	= $row->fields["id_cama"];
			$j++;
			$row->MoveNext();
		}
	}

	return $eventcama;
}





function getFirstDayOfMonthPosition($Xday, $month, $year) {  //OK
	$weekpos = date("w",mktime(0,0,0,$month,$Xday,$year));

	//	if ($weekpos > 0) {
	//		$weekpos = $weekpos - 2;
	//	}

	//print "$weekpos<hr>";
	return abs($weekpos);
}
?>
